require('../@babel/runtime/helpers/Arrayincludes.js');
var t = require('4431DC8470B67DCF2257B4836ACF0B27.js'),
  i = t.blankChar,
  s = require('4975B38470B67DCF2F13DB832AAF0B27.js'),
  e = wx.getSystemInfoSync().windowWidth;
function a(i) {
  var a = this,
    r = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
  (this.attrs = {}),
    (this.CssHandler = new s(r.tagStyle, e)),
    (this.data = i),
    (this.domain = r.domain),
    (this.DOM = []),
    (this.i = this.start = this.audioNum = this.imgNum = this.videoNum = 0),
    (r.prot = (this.domain || '').includes('://')
      ? this.domain.split('://')[0]
      : 'http'),
    (this.options = r),
    (this.state = this.Text),
    (this.STACK = []),
    (this.bubble = function () {
      for (var i, s = a.STACK.length; (i = a.STACK[--s]); ) {
        if (t.richOnlyTags[i.name])
          return (
            'table' != i.name ||
              Object.hasOwnProperty.call(i, 'c') ||
              (i.c = 1),
            !1
          );
        i.c = 1;
      }
      return !0;
    }),
    (this.decode = function (i, s) {
      for (
        var e, a, r = -1;
        -1 != (r = i.indexOf('&', r + 1)) && -1 != (e = i.indexOf(';', r + 2));

      )
        '#' == i[r + 1]
          ? ((a = parseInt(
              ('x' == i[r + 2] ? '0' : '') + i.substring(r + 2, e),
            )),
            isNaN(a) ||
              (i = i.substr(0, r) + String.fromCharCode(a) + i.substr(e + 1)))
          : ((a = i.substring(r + 1, e)),
            (t.entities[a] || a == s) &&
              (i = i.substr(0, r) + (t.entities[a] || '&') + i.substr(e + 1)));
      return i;
    }),
    (this.getUrl = function (t) {
      return (
        '/' == t[0]
          ? '/' == t[1]
            ? (t = a.options.prot + ':' + t)
            : a.domain && (t = a.domain + t)
          : a.domain &&
            0 != t.indexOf('data:') &&
            !t.includes('://') &&
            (t = a.domain + '/' + t),
        t
      );
    }),
    (this.isClose = function () {
      return (
        '>' == a.data[a.i] || ('/' == a.data[a.i] && '>' == a.data[a.i + 1])
      );
    }),
    (this.section = function () {
      return a.data.substring(a.start, a.i);
    }),
    (this.parent = function () {
      return a.STACK[a.STACK.length - 1];
    }),
    (this.siblings = function () {
      return a.STACK.length ? a.parent().children : a.DOM;
    });
}
(a.prototype.parse = function () {
  for (var t; (t = this.data[this.i]); this.i++) this.state(t);
  for (this.state == this.Text && this.setText(); this.STACK.length; )
    this.popNode(this.STACK.pop());
  return this.DOM;
}),
  (a.prototype.setAttr = function () {
    var s = this.attrName.toLowerCase(),
      e = this.attrVal;
    for (
      t.boolAttrs[s]
        ? (this.attrs[s] = 'T')
        : e &&
          ('src' == s || ('data-src' == s && !this.attrs.src)
            ? (this.attrs.src = this.getUrl(this.decode(e, 'amp')))
            : 'href' == s || 'style' == s
              ? (this.attrs[s] = this.decode(e, 'amp'))
              : 'data-' != s.substr(0, 5) && (this.attrs[s] = e)),
        this.attrVal = '';
      i[this.data[this.i]];

    )
      this.i++;
    this.isClose()
      ? this.setNode()
      : ((this.start = this.i), (this.state = this.AttrName));
  }),
  (a.prototype.setText = function () {
    var s,
      e = this.section();
    if (e)
      if (
        ((e =
          (t.onText &&
            t.onText(e, function () {
              return (s = !0);
            })) ||
          e),
        s)
      ) {
        this.data =
          this.data.substr(0, this.start) + e + this.data.substr(this.i);
        var a = this.start + e.length;
        for (this.i = this.start; this.i < a; this.i++)
          this.state(this.data[this.i]);
      } else {
        if (!this.pre) {
          for (var r, h, n = [], o = e.length; (h = e[--o]); )
            i[h]
              ? (' ' != n[0] && n.unshift(' '),
                '\n' == h && null == r && (r = 0))
              : (n.unshift(h), r || (r = 1));
          if (0 == r) return;
          e = n.join('');
        }
        this.siblings().push({ type: 'text', text: this.decode(e) });
      }
  }),
  (a.prototype.setNode = function () {
    var s = { name: this.tagName.toLowerCase(), attrs: this.attrs },
      a = t.selfClosingTags[s.name];
    if (((this.attrs = {}), t.ignoreTags[s.name]))
      if (a)
        if ('source' == s.name) {
          var r = this.parent();
          if (r && ('video' == r.name || 'audio' == r.name) && s.attrs.src)
            u = s.attrs.src.replace('http:', 'https:');
          r.attrs.source.push(u);
        } else 'base' != s.name || this.domain || (this.domain = s.attrs.href);
      else this.remove(s);
    else {
      var h = s.attrs,
        n = this.CssHandler.match(s.name, h, s) + (h.style || ''),
        o = {};
      switch (
        (h.id &&
          (1 & this.options.compress
            ? (h.id = void 0)
            : this.options.useAnchor && this.bubble()),
        2 & this.options.compress && h.class && (h.class = void 0),
        s.name)
      ) {
        case 'a':
        case 'ad':
          this.bubble();
          break;
        case 'font':
          if (
            (h.color && ((o.color = h.color), (h.color = void 0)),
            h.face && ((o['font-family'] = h.face), (h.face = void 0)),
            h.size)
          ) {
            var l = parseInt(h.size);
            l < 1 ? (l = 1) : l > 7 && (l = 7);
            (o['font-size'] = [
              'xx-small',
              'x-small',
              'small',
              'medium',
              'large',
              'x-large',
              'xx-large',
            ][l - 1]),
              (h.size = void 0);
          }
          break;
        case 'embed':
          var d = s.attrs.src || '',
            c = s.attrs.type || '';
          if (
            c.includes('video') ||
            d.includes('.mp4') ||
            d.includes('.3gp') ||
            d.includes('.m3u8')
          )
            s.name = 'video';
          else {
            if (
              !(
                c.includes('audio') ||
                d.includes('.m4a') ||
                d.includes('.wav') ||
                d.includes('.mp3') ||
                d.includes('.aac')
              )
            )
              break;
            s.name = 'audio';
          }
          s.attrs.autostart && (s.attrs.autoplay = 'T'),
            (s.attrs.controls = 'T');
        case 'video':
          s.wasPlay = !1;
        case 'audio':
          if (
            (h.id
              ? this[''.concat(s.name, 'Num')]++
              : (h.id = s.name + ++this[''.concat(s.name, 'Num')]),
            'video' == s.name &&
              (this.videoNum > 3 && (s.lazyLoad = 1),
              h.width &&
                ((o.width =
                  parseFloat(h.width) + (h.width.includes('%') ? '%' : 'px')),
                (h.width = void 0)),
              h.height &&
                ((o.height =
                  parseFloat(h.height) + (h.height.includes('%') ? '%' : 'px')),
                (h.height = void 0))),
            h.controls || h.autoplay || (h.controls = 'T'),
            (h.source = []),
            h.src)
          ) {
            var u = h.src.replace('http:', 'https:');
            h.source.push(u), (h.src = void 0);
          }
          this.bubble();
          break;
        case 'td':
        case 'th':
          if (h.colspan || h.rowspan)
            for (var p, f = this.STACK.length; (p = this.STACK[--f]); )
              if ('table' == p.name) {
                p.c = void 0;
                break;
              }
      }
      h.align && ((o['text-align'] = h.align), (h.align = void 0));
      var m,
        g = n.split(';');
      n = '';
      for (var v = 0, b = g.length; v < b; v++) {
        var x = g[v].split(':');
        if (!(x.length < 2)) {
          var y = x[0].trim().toLowerCase(),
            C = x.slice(1).join(':').trim();
          '-' == C[0] || C.includes('safe')
            ? (n += ';'.concat(y, ':').concat(C))
            : (o[y] && !C.includes('import') && o[y].includes('import')) ||
              (o[y] = C);
        }
      }
      if ('img' == s.name)
        h.src &&
          !h.ignore &&
          (this.bubble()
            ? (h.i = (this.imgNum++).toString())
            : (h.ignore = 'T')),
          h.ignore &&
            ((n += ';-webkit-touch-callout:none'), (o['max-width'] = '100%')),
          o.width
            ? (m = o.width)
            : h.width && (m = h.width.includes('%') ? h.width : h.width + 'px'),
          m &&
            ((o.width = m),
            (h.width = '100%'),
            parseInt(m) > e &&
              ((o.height = ''), h.height && (h.height = void 0))),
          o.height
            ? ((h.height = o.height), (o.height = ''))
            : h.height && !h.height.includes('%') && (h.height += 'px');
      for (var T in o) {
        var w = o[T];
        if (w) {
          if (
            ((T.includes('flex') || 'order' == T || 'self-align' == T) &&
              (s.c = 1),
            w.includes('url'))
          ) {
            var A = w.indexOf('(');
            if (-1 != A++) {
              for (; '"' == w[A] || "'" == w[A] || i[w[A]]; ) A++;
              w = w.substr(0, A) + this.getUrl(w.substr(A));
            }
          } else
            w.includes('rpx')
              ? (w = w.replace(/[0-9.]+\s*rpx/g, function (t) {
                  return (parseFloat(t) * e) / 750 + 'px';
                }))
              : 'white-space' == T &&
                w.includes('pre') &&
                !a &&
                (this.pre = s.pre = !0);
          n += ';'.concat(T, ':').concat(w);
        }
      }
      (n = n.substr(1)) && (h.style = n),
        a
          ? (t.filter && 0 == t.filter(s, this)) || this.siblings().push(s)
          : ((s.children = []),
            'pre' == s.name &&
              t.highlight &&
              (this.remove(s), (this.pre = s.pre = !0)),
            this.siblings().push(s),
            this.STACK.push(s));
    }
    '/' == this.data[this.i] && this.i++,
      (this.start = this.i + 1),
      (this.state = this.Text);
  }),
  (a.prototype.remove = function (s) {
    var e = this,
      a = s.name,
      r = this.i,
      h = function () {
        var t = e.data.substring(r, e.i + 1);
        s.attrs.xmlns || (t = ' xmlns="http://www.w3.org/2000/svg"' + t);
        for (var i = r; '<' != e.data[r]; ) r--;
        t = e.data.substring(r, i).replace('viewbox', 'viewBox') + t;
        var a = e.parent();
        '100%' == s.attrs.width &&
          a &&
          (a.attrs.style || '').includes('inline') &&
          (a.attrs.style = 'width:300px;max-width:100%;' + a.attrs.style),
          e
            .siblings()
            .push({
              name: 'img',
              attrs: {
                src: 'data:image/svg+xml;utf8,' + t.replace(/#/g, '%23'),
                style: (/vertical[^;]+/.exec(s.attrs.style) || []).shift(),
                ignore: 'T',
              },
            });
      };
    if ('svg' == s.name && '/' == this.data[r]) return h(this.i++);
    for (;;) {
      if (-1 == (this.i = this.data.indexOf('</', this.i + 1)))
        return void (this.i = 'pre' == a || 'svg' == a ? r : this.data.length);
      for (this.start = this.i += 2; !i[this.data[this.i]] && !this.isClose(); )
        this.i++;
      if (this.section().toLowerCase() == a)
        return 'pre' == a
          ? ((this.data =
              this.data.substr(0, r + 1) +
              t.highlight(this.data.substring(r + 1, this.i - 5), s.attrs) +
              this.data.substr(this.i - 5)),
            (this.i = r))
          : ('style' == a
              ? this.CssHandler.getStyle(this.data.substring(r + 1, this.i - 7))
              : 'title' == a &&
                (this.DOM.title = this.data.substring(r + 1, this.i - 7)),
            -1 == (this.i = this.data.indexOf('>', this.i)) &&
              (this.i = this.data.length),
            void ('svg' == a && h()));
    }
  }),
  (a.prototype.popNode = function (i) {
    if (i.pre) {
      i.pre = this.pre = void 0;
      for (var s = this.STACK.length; s--; )
        this.STACK[s].pre && (this.pre = !0);
    }
    var e = this.siblings(),
      a = e.length,
      r = i.children;
    if ('head' == i.name || (t.filter && 0 == t.filter(i, this)))
      return e.pop();
    var h = i.attrs;
    if (
      (t.blockTags[i.name]
        ? (i.name = 'div')
        : t.trustTags[i.name] || (i.name = 'span'),
      i.c && ('ul' == i.name || 'ol' == i.name))
    )
      if ((i.attrs.style || '').includes('list-style:none'))
        for (var n, o = 0; (n = r[o++]); ) 'li' == n.name && (n.name = 'div');
      else if ('ul' == i.name) {
        for (var l = 1, d = this.STACK.length; d--; )
          'ul' == this.STACK[d].name && l++;
        if (1 != l) for (var c = r.length; c--; ) r[c].floor = l;
      } else
        for (var u, p = 0, f = 1; (u = r[p++]); )
          'li' == u.name &&
            ((u.type = 'ol'),
            (u.num =
              (function (t, i) {
                if ('a' == i) return String.fromCharCode(97 + ((t - 1) % 26));
                if ('A' == i) return String.fromCharCode(65 + ((t - 1) % 26));
                if ('i' == i || 'I' == i) {
                  t = ((t - 1) % 99) + 1;
                  var s =
                    (['X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC'][
                      Math.floor(t / 10) - 1
                    ] || '') +
                    (['I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'][
                      (t % 10) - 1
                    ] || '');
                  return 'i' == i ? s.toLowerCase() : s;
                }
                return t;
              })(f++, h.type) + '.'));
    if ('table' == i.name) {
      var m = h.cellpadding,
        g = h.cellspacing,
        v = h.border;
      if (
        (i.c &&
          (this.bubble(),
          (h.style = (h.style || '') + ';display:table'),
          m || (m = 2),
          g || (g = 2)),
        v &&
          (h.style = 'border:'
            .concat(v, 'px solid gray;')
            .concat(h.style || '')),
        g &&
          (h.style = 'border-spacing:'.concat(g, 'px;').concat(h.style || '')),
        (v || m || i.c) &&
          (function t(s) {
            for (var e, a = 0; (e = s[a]); a++)
              if ('text' != e.type) {
                var r = e.attrs.style || '';
                i.c &&
                  't' == e.name[0] &&
                  ((e.c = 1),
                  (r +=
                    ';display:table-' +
                    ('th' == e.name || 'td' == e.name
                      ? 'cell'
                      : 'tr' == e.name
                        ? 'row'
                        : 'row-group'))),
                  'th' == e.name || 'td' == e.name
                    ? (v &&
                        (r = 'border:'.concat(v, 'px solid gray;').concat(r)),
                      m && (r = 'padding:'.concat(m, 'px;').concat(r)))
                    : t(e.children || []),
                  r && (e.attrs.style = r);
              }
          })(r),
        this.options.autoscroll)
      ) {
        var b = Object.assign({}, i);
        (i.name = 'div'),
          (i.attrs = { style: 'overflow:scroll' }),
          (i.children = [b]);
      }
    }
    this.CssHandler.pop && this.CssHandler.pop(i),
      'div' != i.name ||
        Object.keys(h).length ||
        1 != r.length ||
        'div' != r[0].name ||
        (e[a - 1] = r[0]);
  }),
  (a.prototype.Text = function (t) {
    if ('<' == t) {
      var i = this.data[this.i + 1],
        s = function (t) {
          return (t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z');
        };
      s(i)
        ? (this.setText(),
          (this.start = this.i + 1),
          (this.state = this.TagName))
        : '/' == i
          ? (this.setText(),
            s(this.data[1 + ++this.i])
              ? ((this.start = this.i + 1), (this.state = this.EndTag))
              : this.Comment())
          : ('!' != i && '?' != i) || (this.setText(), this.Comment());
    }
  }),
  (a.prototype.Comment = function () {
    var t;
    (t =
      '--' == this.data.substring(this.i + 2, this.i + 4)
        ? '--\x3e'
        : '[CDATA[' == this.data.substring(this.i + 2, this.i + 9)
          ? ']]>'
          : '>'),
      -1 == (this.i = this.data.indexOf(t, this.i + 2))
        ? (this.i = this.data.length)
        : (this.i += t.length - 1),
      (this.start = this.i + 1),
      (this.state = this.Text);
  }),
  (a.prototype.TagName = function (t) {
    if (i[t]) {
      for (this.tagName = this.section(); i[this.data[this.i]]; ) this.i++;
      this.isClose()
        ? this.setNode()
        : ((this.start = this.i), (this.state = this.AttrName));
    } else this.isClose() && ((this.tagName = this.section()), this.setNode());
  }),
  (a.prototype.AttrName = function (t) {
    if ('=' == t || i[t] || this.isClose()) {
      if (((this.attrName = this.section()), i[t]))
        for (; i[this.data[++this.i]]; );
      if ('=' == this.data[this.i]) {
        for (; i[this.data[++this.i]]; );
        (this.start = this.i--), (this.state = this.AttrValue);
      } else this.setAttr();
    }
  }),
  (a.prototype.AttrValue = function (t) {
    if ('"' == t || "'" == t) {
      if ((this.start++, -1 == (this.i = this.data.indexOf(t, this.i + 1))))
        return (this.i = this.data.length);
      (this.attrVal = this.section()), this.i++;
    } else {
      for (; !i[this.data[this.i]] && !this.isClose(); this.i++);
      this.attrVal = this.section();
    }
    this.setAttr();
  }),
  (a.prototype.EndTag = function (t) {
    if (i[t] || '>' == t || '/' == t) {
      for (
        var s = this.section().toLowerCase(), e = this.STACK.length;
        e-- && this.STACK[e].name != s;

      );
      if (-1 != e) {
        for (var a; (a = this.STACK.pop()).name != s; ) this.popNode(a);
        this.popNode(a);
      } else
        ('p' != s && 'br' != s) || this.siblings().push({ name: s, attrs: {} });
      (this.i = this.data.indexOf('>', this.i)),
        (this.start = this.i + 1),
        -1 == this.i ? (this.i = this.data.length) : (this.state = this.Text);
    }
  }),
  (module.exports = a);
